/*==============================================================*/
/* DBMS name:      Microsoft SQL Server 2005                    */
/* Created on:     2009-4-12 22:54:01                           */
/*==============================================================*/


if exists (select 1
            from  sysindexes
           where  id    = object_id('sys_Area')
            and   name  = 'Relationship_3_FK'
            and   indid > 0
            and   indid < 255)
   drop index sys_Area.Relationship_3_FK
go

if exists (select 1
            from  sysobjects
           where  id = object_id('sys_Area')
            and   type = 'U')
   drop table sys_Area
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('sys_BusGroupPowerMap')
            and   name  = 'Relationship_10_FK'
            and   indid > 0
            and   indid < 255)
   drop index sys_BusGroupPowerMap.Relationship_10_FK
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('sys_BusGroupPowerMap')
            and   name  = 'Relationship_7_FK'
            and   indid > 0
            and   indid < 255)
   drop index sys_BusGroupPowerMap.Relationship_7_FK
go

if exists (select 1
            from  sysobjects
           where  id = object_id('sys_BusGroupPowerMap')
            and   type = 'U')
   drop table sys_BusGroupPowerMap
go

if exists (select 1
            from  sysobjects
           where  id = object_id('sys_BusinessObject')
            and   type = 'U')
   drop table sys_BusinessObject
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('sys_BusinessObjectPower')
            and   name  = 'Relationship_6_FK'
            and   indid > 0
            and   indid < 255)
   drop index sys_BusinessObjectPower.Relationship_6_FK
go

if exists (select 1
            from  sysobjects
           where  id = object_id('sys_BusinessObjectPower')
            and   type = 'U')
   drop table sys_BusinessObjectPower
go

if exists (select 1
            from  sysobjects
           where  id = object_id('sys_PowerGroup')
            and   type = 'U')
   drop table sys_PowerGroup
go

if exists (select 1
            from  sysobjects
           where  id = object_id('sys_Role')
            and   type = 'U')
   drop table sys_Role
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('sys_RolePowerMap')
            and   name  = 'Relationship_12_FK'
            and   indid > 0
            and   indid < 255)
   drop index sys_RolePowerMap.Relationship_12_FK
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('sys_RolePowerMap')
            and   name  = 'Relationship_11_FK'
            and   indid > 0
            and   indid < 255)
   drop index sys_RolePowerMap.Relationship_11_FK
go

if exists (select 1
            from  sysobjects
           where  id = object_id('sys_RolePowerMap')
            and   type = 'U')
   drop table sys_RolePowerMap
go

if exists (select 1
            from  sysobjects
           where  id = object_id('sys_User')
            and   type = 'U')
   drop table sys_User
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('sys_UserRoleMap')
            and   name  = 'Relationship_9_FK'
            and   indid > 0
            and   indid < 255)
   drop index sys_UserRoleMap.Relationship_9_FK
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('sys_UserRoleMap')
            and   name  = 'Relationship_8_FK'
            and   indid > 0
            and   indid < 255)
   drop index sys_UserRoleMap.Relationship_8_FK
go

if exists (select 1
            from  sysobjects
           where  id = object_id('sys_UserRoleMap')
            and   type = 'U')
   drop table sys_UserRoleMap
go

/*==============================================================*/
/* Table: sys_Area                                              */
/*==============================================================*/
create table sys_Area (
   AreaID               int                  identity,
   UpAreaID             int                  null,
   UpCollection         varchar(100)         null,
   Code                 varchar(100)         null,
   AreaName             varchar(100)         not null,
   constraint PK_SYS_AREA primary key nonclustered (AreaID)
)
go

/*==============================================================*/
/* Index: Relationship_3_FK                                     */
/*==============================================================*/
create index Relationship_3_FK on sys_Area (
UpAreaID ASC
)
go

/*==============================================================*/
/* Table: sys_BusGroupPowerMap                                  */
/*==============================================================*/
create table sys_BusGroupPowerMap (
   PowerId              int                  not null,
   GroupId              int                  not null,
   constraint PK_SYS_BUSGROUPPOWERMAP primary key (PowerId, GroupId)
)
go

/*==============================================================*/
/* Index: Relationship_7_FK                                     */
/*==============================================================*/
create index Relationship_7_FK on sys_BusGroupPowerMap (
GroupId ASC
)
go

/*==============================================================*/
/* Index: Relationship_10_FK                                    */
/*==============================================================*/
create index Relationship_10_FK on sys_BusGroupPowerMap (
PowerId ASC
)
go

/*==============================================================*/
/* Table: sys_BusinessObject                                    */
/*==============================================================*/
create table sys_BusinessObject (
   ClassName            varchar(200)         not null,
   ObjectDesc           varchar(200)         null,
   constraint PK_SYS_BUSINESSOBJECT primary key nonclustered (ClassName)
)
go

/*==============================================================*/
/* Table: sys_BusinessObjectPower                               */
/*==============================================================*/
create table sys_BusinessObjectPower (
   PowerId              int                  not null,
   ClassName            varchar(200)         not null,
   Operation            varchar(20)          not null
      constraint CKC_OPERATION_SYS_BUSI check (Operation in ('A','E','D','G','C')),
   Way                  varchar(2)           not null
      constraint CKC_WAY_SYS_BUSI check (Way in ('A','D')),
   constraint PK_SYS_BUSINESSOBJECTPOWER primary key nonclustered (PowerId)
)
go

/*==============================================================*/
/* Index: Relationship_6_FK                                     */
/*==============================================================*/
create index Relationship_6_FK on sys_BusinessObjectPower (
ClassName ASC
)
go

/*==============================================================*/
/* Table: sys_PowerGroup                                        */
/*==============================================================*/
create table sys_PowerGroup (
   GroupId              int                  not null,
   GruopDesc            varchar(200)         null,
   GruooName            varchar(200)         not null,
   constraint PK_SYS_POWERGROUP primary key nonclustered (GroupId)
)
go

/*==============================================================*/
/* Table: sys_Role                                              */
/*==============================================================*/
create table sys_Role (
   RoleId               int                  identity,
   AreaID               int                  not null,
   RoleName             varchar(200)         not null,
   RoleDesc             varchar(200)         null,
   constraint PK_SYS_ROLE primary key nonclustered (RoleId)
)
go

/*==============================================================*/
/* Table: sys_RolePowerMap                                      */
/*==============================================================*/
create table sys_RolePowerMap (
   GroupId              int                  not null,
   RoleId               int                  not null,
   constraint PK_SYS_ROLEPOWERMAP primary key (GroupId, RoleId)
)
go

/*==============================================================*/
/* Index: Relationship_11_FK                                    */
/*==============================================================*/
create index Relationship_11_FK on sys_RolePowerMap (
GroupId ASC
)
go

/*==============================================================*/
/* Index: Relationship_12_FK                                    */
/*==============================================================*/
create index Relationship_12_FK on sys_RolePowerMap (
RoleId ASC
)
go

/*==============================================================*/
/* Table: sys_User                                              */
/*==============================================================*/
create table sys_User (
   UserID               int                  identity,
   UserName             varchar(100)         null,
   PassWrod             varchar(40)          null,
   EMail                varchar(200)         null,
   RegTime              datetime             null,
   LoginTime            datetime             null,
   constraint PK_SYS_USER primary key nonclustered (UserID)
)
go

/*==============================================================*/
/* Table: sys_UserRoleMap                                       */
/*==============================================================*/
create table sys_UserRoleMap (
   UserID               int                  not null,
   RoleId               int                  not null,
   RoleType             varchar(1)           null,
   constraint PK_SYS_USERROLEMAP primary key (UserID, RoleId)
)
go

/*==============================================================*/
/* Index: Relationship_8_FK                                     */
/*==============================================================*/
create index Relationship_8_FK on sys_UserRoleMap (
RoleId ASC
)
go

/*==============================================================*/
/* Index: Relationship_9_FK                                     */
/*==============================================================*/
create index Relationship_9_FK on sys_UserRoleMap (
UserID ASC
)
go

